/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.eclipsecon.dui.databinding.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import org.eclipsecon.dui.databinding.DBinding;
import org.eclipsecon.dui.databinding.DModel;
import org.eclipsecon.dui.databinding.DatabindingPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>DModel</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.eclipsecon.dui.databinding.impl.DModelImpl#getBindings <em>Bindings</em>}</li>
 *   <li>{@link org.eclipsecon.dui.databinding.impl.DModelImpl#getUiModel <em>Ui Model</em>}</li>
 *   <li>{@link org.eclipsecon.dui.databinding.impl.DModelImpl#getDomainModel <em>Domain Model</em>}</li>
 *   <li>{@link org.eclipsecon.dui.databinding.impl.DModelImpl#getModelRootType <em>Model Root Type</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class DModelImpl extends EObjectImpl implements DModel {
	/**
	 * The cached value of the '{@link #getBindings() <em>Bindings</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBindings()
	 * @generated
	 * @ordered
	 */
	protected EList<DBinding> bindings;

	/**
	 * The default value of the '{@link #getUiModel() <em>Ui Model</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUiModel()
	 * @generated
	 * @ordered
	 */
	protected static final String UI_MODEL_EDEFAULT = null;
	/**
	 * The cached value of the '{@link #getUiModel() <em>Ui Model</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getUiModel()
	 * @generated
	 * @ordered
	 */
	protected String uiModel = UI_MODEL_EDEFAULT;

	/**
	 * The default value of the '{@link #getDomainModel() <em>Domain Model</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDomainModel()
	 * @generated
	 * @ordered
	 */
	protected static final String DOMAIN_MODEL_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getDomainModel() <em>Domain Model</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getDomainModel()
	 * @generated
	 * @ordered
	 */
	protected String domainModel = DOMAIN_MODEL_EDEFAULT;

	/**
	 * The cached value of the '{@link #getModelRootType() <em>Model Root Type</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getModelRootType()
	 * @generated
	 * @ordered
	 */
	protected EClass modelRootType;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected DModelImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return DatabindingPackage.Literals.DMODEL;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<DBinding> getBindings() {
		if (bindings == null) {
			bindings = new EObjectContainmentEList<DBinding>(DBinding.class, this, DatabindingPackage.DMODEL__BINDINGS);
		}
		return bindings;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getUiModel() {
		return uiModel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUiModel(String newUiModel) {
		String oldUiModel = uiModel;
		uiModel = newUiModel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatabindingPackage.DMODEL__UI_MODEL, oldUiModel, uiModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getDomainModel() {
		return domainModel;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setDomainModel(String newDomainModel) {
		String oldDomainModel = domainModel;
		domainModel = newDomainModel;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatabindingPackage.DMODEL__DOMAIN_MODEL, oldDomainModel, domainModel));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass getModelRootType() {
		if (modelRootType != null && modelRootType.eIsProxy()) {
			InternalEObject oldModelRootType = (InternalEObject)modelRootType;
			modelRootType = (EClass)eResolveProxy(oldModelRootType);
			if (modelRootType != oldModelRootType) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, DatabindingPackage.DMODEL__MODEL_ROOT_TYPE, oldModelRootType, modelRootType));
			}
		}
		return modelRootType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EClass basicGetModelRootType() {
		return modelRootType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setModelRootType(EClass newModelRootType) {
		EClass oldModelRootType = modelRootType;
		modelRootType = newModelRootType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, DatabindingPackage.DMODEL__MODEL_ROOT_TYPE, oldModelRootType, modelRootType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case DatabindingPackage.DMODEL__BINDINGS:
				return ((InternalEList<?>)getBindings()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case DatabindingPackage.DMODEL__BINDINGS:
				return getBindings();
			case DatabindingPackage.DMODEL__UI_MODEL:
				return getUiModel();
			case DatabindingPackage.DMODEL__DOMAIN_MODEL:
				return getDomainModel();
			case DatabindingPackage.DMODEL__MODEL_ROOT_TYPE:
				if (resolve) return getModelRootType();
				return basicGetModelRootType();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case DatabindingPackage.DMODEL__BINDINGS:
				getBindings().clear();
				getBindings().addAll((Collection<? extends DBinding>)newValue);
				return;
			case DatabindingPackage.DMODEL__UI_MODEL:
				setUiModel((String)newValue);
				return;
			case DatabindingPackage.DMODEL__DOMAIN_MODEL:
				setDomainModel((String)newValue);
				return;
			case DatabindingPackage.DMODEL__MODEL_ROOT_TYPE:
				setModelRootType((EClass)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case DatabindingPackage.DMODEL__BINDINGS:
				getBindings().clear();
				return;
			case DatabindingPackage.DMODEL__UI_MODEL:
				setUiModel(UI_MODEL_EDEFAULT);
				return;
			case DatabindingPackage.DMODEL__DOMAIN_MODEL:
				setDomainModel(DOMAIN_MODEL_EDEFAULT);
				return;
			case DatabindingPackage.DMODEL__MODEL_ROOT_TYPE:
				setModelRootType((EClass)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case DatabindingPackage.DMODEL__BINDINGS:
				return bindings != null && !bindings.isEmpty();
			case DatabindingPackage.DMODEL__UI_MODEL:
				return UI_MODEL_EDEFAULT == null ? uiModel != null : !UI_MODEL_EDEFAULT.equals(uiModel);
			case DatabindingPackage.DMODEL__DOMAIN_MODEL:
				return DOMAIN_MODEL_EDEFAULT == null ? domainModel != null : !DOMAIN_MODEL_EDEFAULT.equals(domainModel);
			case DatabindingPackage.DMODEL__MODEL_ROOT_TYPE:
				return modelRootType != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (uiModel: ");
		result.append(uiModel);
		result.append(", domainModel: ");
		result.append(domainModel);
		result.append(')');
		return result.toString();
	}

} //DModelImpl
